/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sellcar;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFormattedTextField;

/**
 *
 * @author Marcos
 */
public class Cadastro_Vendedor extends javax.swing.JFrame {

    /**
     * Creates new form Cadastro_Vendedor
     */
    
    private Connection connection;
    
    public Cadastro_Vendedor() {
        
        initComponents();
        
        this.setLocationRelativeTo(null);
        this.connection = new ConnectionFactory().getConnection();
        
        try {
            mostrar();
        } catch (SQLException ex) {
            Logger.getLogger(Cadastro_Vendedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void limparTodosCampos(Container container) {  
    Component components[] = container.getComponents();  
    for (Component component : components) {  
        if (component instanceof JFormattedTextField) {  
            JFormattedTextField field = (JFormattedTextField) component;  
            field.setValue(null);  
        } else if (component instanceof JTextField) {  
            JTextField field = (JTextField) component;  
            field.setText("");  
        } else if (component instanceof Container) {  
            limparTodosCampos((Container) component);  
        }  
    }  
}  
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Nome = new javax.swing.JLabel();
        RG = new javax.swing.JLabel();
        CPF = new javax.swing.JLabel();
        DtNasc = new javax.swing.JLabel();
        Cel1 = new javax.swing.JLabel();
        Cel2 = new javax.swing.JLabel();
        Tel1 = new javax.swing.JLabel();
        Tel2 = new javax.swing.JLabel();
        Email = new javax.swing.JLabel();
        End = new javax.swing.JLabel();
        Comp = new javax.swing.JLabel();
        UF = new javax.swing.JLabel();
        CEP = new javax.swing.JLabel();
        TitMenu = new javax.swing.JLabel();
        Bairro = new javax.swing.JLabel();
        Cidade = new javax.swing.JLabel();
        TxtNome = new javax.swing.JTextField();
        TxtEmail = new javax.swing.JTextField();
        TxtEnd = new javax.swing.JTextField();
        TxtComp = new javax.swing.JTextField();
        TxtUF = new javax.swing.JTextField();
        TxtBairro = new javax.swing.JTextField();
        TxtCid = new javax.swing.JTextField();
        BtSalvar = new javax.swing.JButton();
        BtExcluir = new javax.swing.JButton();
        BtVoltar = new javax.swing.JButton();
        TxtRG = new javax.swing.JFormattedTextField();
        TxtCPF = new javax.swing.JFormattedTextField();
        TxtCel2 = new javax.swing.JFormattedTextField();
        TxtCel1 = new javax.swing.JFormattedTextField();
        TxtTel1 = new javax.swing.JFormattedTextField();
        TxtTel2 = new javax.swing.JFormattedTextField();
        TxtCEP = new javax.swing.JFormattedTextField();
        TxtDtnasc = new javax.swing.JFormattedTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        Nome.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Nome.setText("Nome: ");

        RG.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RG.setText("RG:");

        CPF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CPF.setText("CPF:");

        DtNasc.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DtNasc.setText("Dt. Nascimento");

        Cel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Cel1.setText("Cel:");

        Cel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Cel2.setText("Cel:");

        Tel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Tel1.setText("Tel:");

        Tel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Tel2.setText("Te:l");

        Email.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Email.setText("E-mail:");

        End.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        End.setText("Endereço:");

        Comp.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Comp.setText("Compl:");

        UF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        UF.setText("UF:");

        CEP.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CEP.setText("CEP:");

        TitMenu.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        TitMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TitMenu.setText("CADASTRO DE VENDEDOR");

        Bairro.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Bairro.setText("Bairro:");

        Cidade.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Cidade.setText("Cidade:");

        TxtNome.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtNome.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        TxtEmail.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtEmail.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        TxtEnd.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtEnd.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        TxtComp.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtComp.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        TxtUF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtUF.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        TxtBairro.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        TxtCid.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        BtSalvar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BtSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/document_save_as.png"))); // NOI18N
        BtSalvar.setMnemonic('S');
        BtSalvar.setText("Salvar");
        BtSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtSalvarActionPerformed(evt);
            }
        });

        BtExcluir.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BtExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/delete.png"))); // NOI18N
        BtExcluir.setMnemonic('E');
        BtExcluir.setText("Limpar");
        BtExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtExcluirActionPerformed(evt);
            }
        });

        BtVoltar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BtVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/arrow_left.png"))); // NOI18N
        BtVoltar.setMnemonic('S');
        BtVoltar.setText("Voltar");
        BtVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtVoltarActionPerformed(evt);
            }
        });

        try {
            TxtRG.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###-#")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtRG.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        try {
            TxtCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtCPF.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        try {
            TxtCel2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)#####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtCel2.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        try {
            TxtCel1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)#####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtCel1.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        TxtCel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtCel1ActionPerformed(evt);
            }
        });

        try {
            TxtTel1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtTel1.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        try {
            TxtTel2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtTel2.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        try {
            TxtCEP.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtCEP.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        try {
            TxtDtnasc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtDtnasc.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/pencil.png"))); // NOI18N
        jButton1.setText("Alterar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/delete.png"))); // NOI18N
        jButton2.setText("Excluir");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/find.png"))); // NOI18N
        jButton3.setText("Pesquisar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/resultset_previous.png"))); // NOI18N
        jButton4.setText("Anterior");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/resultset_next.png"))); // NOI18N
        jButton5.setText("Proximo");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(TitMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Nome)
                            .addComponent(RG)
                            .addComponent(Cel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(TxtCel1, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                                    .addComponent(TxtRG))
                                .addGap(27, 27, 27)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(CPF)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(TxtCPF)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(DtNasc)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(TxtDtnasc, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(Tel2)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(TxtTel2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(Cel2)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(TxtCel2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addComponent(TxtNome)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Comp)
                            .addComponent(Bairro))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(TxtComp, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(UF)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(TxtUF, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(CEP)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(TxtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(TxtBairro))
                        .addGap(18, 18, 18)
                        .addComponent(Cidade)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TxtCid))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Tel1)
                        .addGap(29, 29, 29)
                        .addComponent(TxtTel1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Email)
                            .addComponent(End))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TxtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE)
                            .addComponent(TxtEnd)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(67, 67, 67)
                                .addComponent(BtSalvar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(BtExcluir))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(140, 140, 140)
                                .addComponent(jButton3)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BtVoltar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(TitMenu)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Nome)
                    .addComponent(TxtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RG)
                    .addComponent(CPF)
                    .addComponent(DtNasc)
                    .addComponent(TxtRG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TxtCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TxtDtnasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Cel1)
                    .addComponent(Cel2)
                    .addComponent(TxtCel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TxtCel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Tel1)
                    .addComponent(TxtTel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Tel2)
                    .addComponent(TxtTel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Email)
                    .addComponent(TxtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(End))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Comp)
                    .addComponent(TxtComp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(UF)
                    .addComponent(TxtUF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CEP)
                    .addComponent(TxtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Cidade)
                    .addComponent(TxtCid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Bairro)
                    .addComponent(TxtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtSalvar)
                    .addComponent(BtExcluir)
                    .addComponent(BtVoltar)
                    .addComponent(jButton5)
                    .addComponent(jButton4))
                .addGap(21, 21, 21))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BtVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtVoltarActionPerformed
        // Botão Voltar
        // Encerra a tela de cadastro
        this.dispose();
    }//GEN-LAST:event_BtVoltarActionPerformed

    private void TxtCel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtCel1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TxtCel1ActionPerformed

    private void BtSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtSalvarActionPerformed
        // TODO add your handling code here:
        
        //BOTAO SALVAR
        
        Vendedor vendedor = new Vendedor();
        
        vendedor.setCep(TxtCEP.getText().replaceAll("\\D", ""));
        vendedor.setCpf(TxtCPF.getText().replaceAll("\\D", ""));
        vendedor.setCel1(TxtCel1.getText().replaceAll("\\D", ""));
        vendedor.setCel2(TxtCel2.getText().replaceAll("\\D", ""));
        vendedor.setComp(TxtComp.getText());
        vendedor.setDtnasc(TxtDtnasc.getText());
        vendedor.setEmail(TxtEmail.getText());
        vendedor.setEnd(TxtEnd.getText());
        vendedor.setNome(TxtNome.getText());
        vendedor.setRg(TxtRG.getText().replaceAll("\\D", ""));
        vendedor.setTel1(TxtTel1.getText().replaceAll("\\D", ""));
        vendedor.setTel2(TxtTel2.getText().replaceAll("\\D", ""));
        vendedor.setUf(TxtUF.getText());
        vendedor.setBairro(TxtBairro.getText());
        vendedor.setCid(TxtCid.getText());
                
        Cadastro_VendedorDAO cadastro_vendedorDAO = new Cadastro_VendedorDAO();
        
        
        cadastro_vendedorDAO.adiciona(vendedor);
        JOptionPane.showMessageDialog(null,"Vendedor Gravado com Sucesso");
        
    }//GEN-LAST:event_BtSalvarActionPerformed

    private void BtExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtExcluirActionPerformed
        // TODO add your handling code here:
        limparTodosCampos(rootPane);
    }//GEN-LAST:event_BtExcluirActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        
        try {
            // TODO add your handling code here:
            
            //BOTAO PESQUISAR
            
            rsMostrar.first();
            
            String id = rsMostrar.getString("COD_CADASTRO");    
            TxtBairro.setText(rsMostrar.getString("BAIRRO"));
            TxtCPF.setText(rsMostrar.getString("CPF"));
            TxtCel1.setText(rsMostrar.getString("TEL_CEL_1"));
            TxtCel2.setText(rsMostrar.getString("TEL_CEL_2"));
            TxtCid.setText(rsMostrar.getString("CIDADE"));
            TxtComp.setText(rsMostrar.getString("COMPL"));
            TxtDtnasc.setText(rsMostrar.getString("DT_NASC"));
            TxtEmail.setText(rsMostrar.getString("EMAIL"));
            TxtEnd.setText(rsMostrar.getString("ENDERECO"));
            TxtNome.setText(rsMostrar.getString("NOME"));
            TxtRG.setText(rsMostrar.getString("RG"));
            TxtTel1.setText(rsMostrar.getString("TEL_1"));
            TxtTel2.setText(rsMostrar.getString("TEL_2"));
            TxtUF.setText(rsMostrar.getString("UF"));
            TxtCEP.setText(rsMostrar.getString("CEP"));
            
        } catch (SQLException ex) {
            Logger.getLogger(Cadastro_Vendedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        
        //BOTAO DELETAR REGISTRO
        
        PreparedStatement stmt;
        
        try {            
            String id = rsMostrar.getString("COD_CADASTRO");
            
            String sql = "delete from sellcar_db.tb_cadastro_vendedor  where COD_CADASTRO = " + Integer.parseInt(id);
            stmt = connection.prepareStatement(sql);
            stmt.execute();
            stmt.close();
            
            JOptionPane.showMessageDialog(null,"Usuario deletado do sistema");
            mostrar();
//                rs.close();
//                stmt.close();
//                connection.close();
        } catch (SQLException ex) {
            Logger.getLogger(Cadastro_Usuario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        try {
            // TODO add your handling code here:
            
            //BOTAO ANTERIOR
            
            rsMostrar.previous();
            
            TxtBairro.setText(rsMostrar.getString("BAIRRO"));
            TxtCPF.setText(rsMostrar.getString("CPF"));
            TxtCel1.setText(rsMostrar.getString("TEL_CEL_1"));
            TxtCel2.setText(rsMostrar.getString("TEL_CEL_2"));
            TxtCid.setText(rsMostrar.getString("CIDADE"));
            TxtComp.setText(rsMostrar.getString("COMPL"));
            TxtDtnasc.setText(rsMostrar.getString("DT_NASC"));
            TxtEmail.setText(rsMostrar.getString("EMAIL"));
            TxtEnd.setText(rsMostrar.getString("ENDERECO"));
            TxtNome.setText(rsMostrar.getString("NOME"));
            TxtRG.setText(rsMostrar.getString("RG"));
            TxtTel1.setText(rsMostrar.getString("TEL_1"));
            TxtTel2.setText(rsMostrar.getString("TEL_2"));
            TxtUF.setText(rsMostrar.getString("UF"));
            TxtCEP.setText(rsMostrar.getString("CEP"));
            
        } catch (SQLException ex) {
            Logger.getLogger(Cadastro_Vendedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        try {
            // TODO add your handling code here:
            
            //BOTAO PROXIMO
            
            rsMostrar.next();
            
            TxtBairro.setText(rsMostrar.getString("BAIRRO"));
            TxtCPF.setText(rsMostrar.getString("CPF"));
            TxtCel1.setText(rsMostrar.getString("TEL_CEL_1"));
            TxtCel2.setText(rsMostrar.getString("TEL_CEL_2"));
            TxtCid.setText(rsMostrar.getString("CIDADE"));
            TxtComp.setText(rsMostrar.getString("COMPL"));
            TxtDtnasc.setText(rsMostrar.getString("DT_NASC"));
            TxtEmail.setText(rsMostrar.getString("EMAIL"));
            TxtEnd.setText(rsMostrar.getString("ENDERECO"));
            TxtNome.setText(rsMostrar.getString("NOME"));
            TxtRG.setText(rsMostrar.getString("RG"));
            TxtTel1.setText(rsMostrar.getString("TEL_1"));
            TxtTel2.setText(rsMostrar.getString("TEL_2"));
            TxtUF.setText(rsMostrar.getString("UF"));
            TxtCEP.setText(rsMostrar.getString("CEP"));
        } catch (SQLException ex) {
            Logger.getLogger(Cadastro_Vendedor.class.getName()).log(Level.SEVERE, null, ex);
        }            

    }//GEN-LAST:event_jButton5ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                
                new Cadastro_Vendedor().setVisible(true);                
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Bairro;
    private javax.swing.JButton BtExcluir;
    private javax.swing.JButton BtSalvar;
    private javax.swing.JButton BtVoltar;
    private javax.swing.JLabel CEP;
    private javax.swing.JLabel CPF;
    private javax.swing.JLabel Cel1;
    private javax.swing.JLabel Cel2;
    private javax.swing.JLabel Cidade;
    private javax.swing.JLabel Comp;
    private javax.swing.JLabel DtNasc;
    private javax.swing.JLabel Email;
    private javax.swing.JLabel End;
    private javax.swing.JLabel Nome;
    private javax.swing.JLabel RG;
    private javax.swing.JLabel Tel1;
    private javax.swing.JLabel Tel2;
    private javax.swing.JLabel TitMenu;
    private javax.swing.JTextField TxtBairro;
    private javax.swing.JFormattedTextField TxtCEP;
    private javax.swing.JFormattedTextField TxtCPF;
    private javax.swing.JFormattedTextField TxtCel1;
    private javax.swing.JFormattedTextField TxtCel2;
    private javax.swing.JTextField TxtCid;
    private javax.swing.JTextField TxtComp;
    private javax.swing.JFormattedTextField TxtDtnasc;
    private javax.swing.JTextField TxtEmail;
    private javax.swing.JTextField TxtEnd;
    private javax.swing.JTextField TxtNome;
    private javax.swing.JFormattedTextField TxtRG;
    private javax.swing.JFormattedTextField TxtTel1;
    private javax.swing.JFormattedTextField TxtTel2;
    private javax.swing.JTextField TxtUF;
    private javax.swing.JLabel UF;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    // End of variables declaration//GEN-END:variables
    
    ResultSet rsMostrar = null;
    
    private int atual = 0;
    private int total = 0;

    public ResultSet mostrar() throws SQLException {

        PreparedStatement stmt;

        String sql = "SELECT COD_CADASTRO,NOME,RG,CPF,DT_NASC,TEL_1,TEL_2,TEL_CEL_1,TEL_CEL_2,EMAIL,ENDERECO,BAIRRO,CIDADE,COMPL,CEP,UF FROM sellcar_db.tb_cadastro_vendedor";
        stmt = connection.prepareStatement(sql);
        rsMostrar = stmt.executeQuery(sql);
        while (rsMostrar.next()) {
            total = total + 1;
            //JOptionPane.showMessageDialog(null, rsMostrar.getString(1));
        }
        //rsMostrar.first();
        return rsMostrar;

    }
}
